### Agreeableness

agreeableness <- mapply(as.numeric,with(wvs_sub,data.frame(
  agre1,
  agre2,
  agre3, 
  agre4, 
  agre5, 
  agre6, 
  agre7, 
  agre8, 
  agre9,
  agre10)))

psych::alpha(agreeableness,check.keys = T)
agreeablenesslist <- list()
a <- 0
for(i in 1:9){
  a <- a+(ncol(combn(1:10, i)))
}

b <- 0
items <- list()
for(j in 1:9){
  b=b+1 
  combos <- combn(1:10, j)
  for(i in 1:ncol(combos)){
    items[[b]] <- combos
  }}

itemrow <- lapply(items,nrow)
itemcol <- lapply(items,ncol)

collapsepastecolumns <- function(x)apply(x,2,paste,collapse=",")
rr <- lapply(collapsepastecolumns,X = items)

numbero <-   unlist(itemcol)
emptylist <- list()  
for(i in 2:9){
  emptylist[[i-1]] <- rep(i,numbero[[i-1]])
}

h=1
j=2
i=1
alphacoefs <- data.frame(matrix(nrow=1012,ncol=4))

for(j in 2:9){
  combos <- combn(1:10, j)
  two <- matrix(nrow=nrow(wvs_sub),ncol=ncol(combos))
  for(i in 1:ncol(combos)){
    two[,i] <-   rowMeans(agreeableness[,combos[,i]])
    alphacoefs[h,] <- psych::alpha(agreeableness[,combos[,i]],check.keys = TRUE)$total[1:4]
    h=  h+1
  }
  lmcoefs <- matrix(nrow=ncol(combos),ncol=3)
  for(i in 1:ncol(two)){
    lmcoefs[i,1]   <-   lm(zero1(wvs_sub$wvs_lrplacement)~zero1(two[,i])+wvs_sub$IPIP_con+wvs_sub$IPIP_ext+wvs_sub$IPIP_open+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+ wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
    lmcoefs[i,2]   <-   lm(zero1(wvs_sub$wvs_moral)~zero1(two[,i])+wvs_sub$IPIP_con+wvs_sub$IPIP_ext+wvs_sub$IPIP_open+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+ wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
    lmcoefs[i,3]   <-   lm(zero1(wvs_sub$wvs_economicattitudes)~zero1(two[,i])+wvs_sub$IPIP_con+wvs_sub$IPIP_ext+wvs_sub$IPIP_open+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+ wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
  }
  agreeablenesslist[[j]] <- lmcoefs
  
}
lmcoefs <- matrix(ncol=3)
## 10 item s
lmcoefs[1]   <-   lm(zero1(wvs_sub$wvs_lrplacement)~zero1(rowMeans(agreeableness))+wvs_sub$IPIP_con+wvs_sub$IPIP_ext+wvs_sub$IPIP_open+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+ wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
lmcoefs[2]   <-   lm(zero1(wvs_sub$wvs_moral)~zero1(rowMeans(agreeableness))+  wvs_sub$IPIP_con+wvs_sub$IPIP_ext+wvs_sub$IPIP_open+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+ wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
lmcoefs[3]   <-   lm(zero1(wvs_sub$wvs_economicattitudes)~zero1(rowMeans(agreeableness))+  wvs_sub$IPIP_open+wvs_sub$IPIP_con+wvs_sub$IPIP_ext+wvs_sub$IPIP_open+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+ wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]

agreeablenesslist[[10]] <- lmcoefs
alphacoefs[1013,] <- psych::alpha(agreeableness,check.keys = TRUE)$total[1:4]


lmcoefs <- matrix(nrow=10,ncol=3)

for(i in 1:ncol(agreeableness)){
  lmcoefs[i,1]   <-   lm(zero1(wvs_sub$wvs_lrplacement)~zero1((agreeableness)[,i])+  wvs_sub$IPIP_open+wvs_sub$IPIP_con+wvs_sub$IPIP_ext+wvs_sub$IPIP_open+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+ wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
  lmcoefs[i,2]   <-   lm(zero1(wvs_sub$wvs_moral)~zero1((agreeableness)[,i])+  wvs_sub$IPIP_open+wvs_sub$IPIP_con+wvs_sub$IPIP_ext+wvs_sub$IPIP_open+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+ wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
  lmcoefs[i,3]   <-   lm(zero1(wvs_sub$wvs_economicattitudes)~zero1((agreeableness)[,i])+  wvs_sub$IPIP_open+wvs_sub$IPIP_con+wvs_sub$IPIP_ext+wvs_sub$IPIP_open+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+ wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
}
agreeablenesslist[[1]] <- lmcoefs

l <- Map(cbind, agreeablenesslist, indx = seq_len(length(agreeablenesslist))) 
h <- data.frame(do.call(rbind, l))
head(h )
names(h) <- c("Left-Right","Moral","Economic Ideology","Index")
empties <- data.frame(matrix(NA,nrow = 10,ncol = 4))
colnames(empties) <- colnames(alphacoefs)
alphacoefs <- rbind(empties,alphacoefs)
itemstogether <- unlist(rr)
itemstogether[1023] <- "all"
numall <- unlist(emptylist)
outstanding <- data.frame(h,itemstogether,alphacoefs)
library(reshape2)
forfig <- melt(outstanding,id.vars=c("Index","itemstogether",names(empties)))
forfig$trait <- "Agreeableness"



